package com.xca.is.repository;

import com.xca.is.entity.Courier;
import com.xca.is.service.CourierService;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.schedulers.Schedulers;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class CourierRepository {
    private static final String URL = "https://xiaoapi.cn/API/" ;
    private CourierService service ;
    public CourierRepository(){
            new Thread(new Runnable() {
                @Override
                public void run() {
                    Retrofit retrofit = new Retrofit.Builder()
                            .baseUrl(URL)
                            .addCallAdapterFactory(RxJava3CallAdapterFactory.create())
                            .addConverterFactory(GsonConverterFactory.create())
                            .build() ;
                    service = retrofit.create(CourierService.class) ;
                }
            }).start();

    }

    public Observable<Courier> getData(String num , String phone){
        return service.getData(num , phone)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io()) ;
    }
}
